package lab02.test23;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) {

        String birthday;

        System.out.println("Please inout your birthday:");
        Scanner scanner = new Scanner(System.in);
        birthday = scanner.nextLine();

        /**
         *
         * 2017-10-20   -> long time1  毫秒
         * 2017-11-10   -> ling time2
         *
         */
        long time1 = 0;
        long time2 = 0;

        /**
         * 实例化
         * Student chen = new Student();
         * Study study = new Study();
         * Calerdar calendar = Calerdar.getInstance();
         *
         *
         * 字符串 ->  simpleDateFormat --> Date   -->  calendar --> Long
         */


        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        try {
            Date birthDay = simpleDateFormat.parse(birthday);
            Date currentDAte = simpleDateFormat.parse(simpleDateFormat.format(calendar.getTime()));

            calendar.setTime(birthDay);
            time1 = calendar.getTimeInMillis();

            calendar.setTime(currentDAte);
            time2 =  calendar.getTimeInMillis();

        } catch (ParseException e) {
            e.printStackTrace();
        }

        long days = (time1-time2)/(24*60*60*1000);

        System.out.println("相差天数是"+days);

    }
}
